package properties_redis

import (
	"MoSkeleton/framework/core/consts"
	"github.com/redis/go-redis/v9"
)

/*
*
配置参数，详见：https://redis.uptrace.dev/zh/guide/ring.html#%E4%BB%8B%E7%BB%8D
*/
type RedisProperty struct {
	Enable     bool                 `mapstructure:"enable" json:"enable" yaml:"enable"`
	Mode       string               `mapstructure:"mode" json:"mode" yaml:"mode"`
	KeyPrefix  string               `mapstructure:"key-prefix" json:"key-prefix" yaml:"key-prefix"`
	Standalone redis.Options        `mapstructure:"standalone" json:"standalone" yaml:"standalone"`
	Cluster    redis.ClusterOptions `mapstructure:"cluster" json:"cluster" yaml:"cluster"`
	// db 配置不可用,默认：0
	Sentinel redis.FailoverOptions `mapstructure:"sentinel" json:"sentinel" yaml:"sentinel"`
	Shard    redis.RingOptions     `mapstructure:"shard" json:"shard" yaml:"shard"`
}

func (r *RedisProperty) GetMode() string {
	if r.Mode == "" {
		return consts.RedisMode_Standalone
	}
	return r.Mode
}
